#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

import lightcloud

LIGHT_CLOUD = {
    'lookup1_A': [ '127.0.0.1:41201', '127.0.0.1:51201' ],
    'lookup2_A': [ '127.0.0.1:42201', '127.0.0.1:52201' ],
    'storage1_A': [ '127.0.0.1:44201', '127.0.0.1:54201' ],
    'storage2_A': [ '127.0.0.1:45201', '127.0.0.1:55201' ],
    'storage3_A': [ '127.0.0.1:46201', '127.0.0.1:56201' ],
}

lookup_nodes, storage_nodes = lightcloud.generate_nodes(LIGHT_CLOUD)
lightcloud.init(lookup_nodes, storage_nodes)

lightcloud.set_storage_index('id', lightcloud.IndexType.LEXICAL)

for i in range(1000):
  lightcloud.set(str(i), {"id": str(i)}, True)
lightcloud.set("1", {"foo": "bar"})
for i in range(10):
  print lightcloud.get(str(i))

q = lightcloud.Query()
q.add_cond('foo', lightcloud.QueryCondition.STREQ, 'bar')
print lightcloud.query(q)

q = lightcloud.Query()
q.add_cond('id', lightcloud.QueryCondition.NUMLE, '500')
q.set_limit(10)
q.set_order('id', lightcloud.QueryOrder.NUMASC)
from pprint import pprint
pprint(lightcloud.query(q, True))
q.set_limit(100)
pprint(lightcloud.query(q, ['id']))
